/**
 * @author Tobias Boehm
 *
 * 16.05.2011
 */
package org.anddev.andengine.extension.tbsengine.message.client.preparematch;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.anddev.andengine.extension.tbsengine.faction.AbsBaseFaction;
import org.anddev.andengine.extension.tbsengine.message.ICopyable;

/**
 * This client message should be used to request a faction change on a specific
 * player slot.
 * 
 * @author Tobias Boehm
 *
 */
public class ClientSlotChangeFactionRequestMessage extends AbsClientSlotChangeRequestMessage implements ICopyable<ClientSlotChangeFactionRequestMessage>{

	private String mFactionID = "";

	
	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.multiplayer.protocol.adt.message.IMessage#getFlag()
	 */
	@Override
	public short getFlag() {
		
		return FLAG_CLIENT_SLOT_CHANGE_FACTION_REQUEST;
	}

	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.tbsengine.multiplayer.client.messages.preparematch.AbsClientSlotRequestMessage#onReadTransmissionClientSlotRequestData(java.io.DataInputStream)
	 */
	@Override
	protected void onReadTransmissionClientSlotRequestData(
			DataInputStream pDataInputStream) throws IOException {
		
		this.mFactionID = pDataInputStream.readUTF();

	}

	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.tbsengine.multiplayer.client.messages.preparematch.AbsClientSlotRequestMessage#onWriteTransmissionClientSlotRequestData(java.io.DataOutputStream)
	 */
	@Override
	protected void onWriteTransmissionClientSlotRequestData(
			DataOutputStream pDataOutputStream) throws IOException {
		
		pDataOutputStream.writeUTF(this.mFactionID);
	}

	/**
	 * @return the mFactionID
	 */
	public String getNewFactionID() {
		return mFactionID;
	}

	/**
	 * @param mFactionID the mFactionID to set
	 */
	public void setNewFaction(final AbsBaseFaction pNewFaction) {
		this.mFactionID = pNewFaction.getFactionIDname();
	}

	@Override
	public ClientSlotChangeFactionRequestMessage copy() {
		
		final ClientSlotChangeFactionRequestMessage copy = new ClientSlotChangeFactionRequestMessage();
		
		copy.mFactionID = this.mFactionID;
		copy.mMatchID = this.mMatchID;
		copy.mPlayerID = this.mPlayerID;
		copy.mSlotID = this.mSlotID;
		
		return copy;
	}
}
